/**Author:7rATM Team
 *Date:May 2009
 *Description: The class BankAccountDB models a database of bank accounts. It uses a  *collection of bankAccount instances
 */

package AtmSystem;

import java.util.*;

public class BankAccountDB {

       /* Collection of <code>bankAccounts</code> objects.*/
       private Vector<BankAccount> bankAccounts;
       /**
        *Constructs an empty backacccounts database.
        */
       public BankAccountDB ()
		{
		bankAccounts=new Vector();
		}


    /**
     * Adds a {@link BankAccount} object to this bank acccounts database.
     *
     * @param newBankAccount  the {@link BankAccount} object.
     */
	public boolean add(BankAccount newBankAccount)
		{
			return bankAccounts.add(newBankAccount);
		}

    /**
     * Removes a {@link BankAccountDB} object from this collection
     * and sets the {@link BankAccountDB} object as available.
     *
     * @param number  the {@link BankAccountDB} object.
     * @return <code>ture</code> if card number is exit ;
     * return  <code>false</code>otherwises.
     */
	public boolean removeb(int newCardNumber)
		{
		BankAccount removedBankAccount =isExsit(newCardNumber);
		if(removedBankAccount != null)
			{
			bankAccounts.remove(removedBankAccount);
			return true;
			}
			return false;
		}

		public boolean remove(BankAccount newBankAccount)
		{
			return bankAccounts.remove(newBankAccount);
		}

          /**
	   * @return the index of card number if newCardNumber equals to a cardnumber             * of bankAccounts
	   * return null otherwise
	   */
		public BankAccount isExsit(int newCardNumber)
		{
			for(int index = 0;index<getNumbers();index ++)
			{
				if (bankAccounts.get(index).getCardNumber() == newCardNumber)
				{
					return (BankAccount) (bankAccounts.get(index) );
				}
			}
			return null;
		}

    /**
     * Returns the number of bank accounts 
     *
     * @return  the number of bank accounts .
     */
    	public int getNumbers()
		{
		return bankAccounts.size();
		}
    /**
     * Returns the index of bank accounts 
     *
     * @return  the index of bank accounts .
     */		
		public BankAccount get(int index)
		{
			return bankAccounts.get(index);
		}
}
